__author__ = 'Marc Huisinga'

from vlsm_subnetter import vlsm_subnetter


def display_menu():
    """
    Displays the input helper menu.
    :return: data input by the user
    """
    input_data = []
    network_address = input("CIDR IPv4 address of the network to subnet: ")
    input_data.append(network_address)
    print()
    output_choice = input("Output to .csv file instead of console ([Y]/n)? ")
    if output_choice != "n":
        output_location = input("Output location: ")
        input_data.append("-o")
        input_data.append(output_location)
    print()
    continuation_choice = "Y"
    while continuation_choice != "n":
        name = input("Name of the subnet: ")
        expected_hosts = input("Hosts expected in the subnet: ")
        subnet_count = input("Amount of subnets of this type [1]: ")
        input_data.append("%s,%s,%s" % (name, expected_hosts, subnet_count)
                          if subnet_count != "" else
                          "%s,%s" % (name, expected_hosts))
        continuation_choice = input("Build another subnet ([Y]/n)? ")
        print()
    return input_data


def help_with_input():
    """
    Helps with the input of vlsm_subnetter to get rid of command line arguments.
    """
    try:
        input_data = display_menu()
        vlsm_subnetter.start_vlsm_subnetter(args=input_data)
        input()
    except KeyboardInterrupt:
        print("Interrupted.")


if __name__ == "__main__":
    help_with_input()